import axios from 'axios'
import { CHANGE_HOME_DATA, ADD_HOME_LIST, TOGGLE_SCROLL_TOP } from './actionTypes'
import { fromJS } from 'immutable'
const changeHomeData = (result) => ({
    type: CHANGE_HOME_DATA,
    topicList: result.topicList,
    articleList: result.articleList,
    recommendList: result.recommendList
})
const addHomeList = (list, nextPage) => ({
    type: ADD_HOME_LIST,
    list: fromJS(list),
    nextPage

})
export const getHomeInfo = () => {
    return (dispatch) => {
        axios.get('/api/home.json').then((res) => {
            const result = res.data.data;
            const action = changeHomeData(result)
            // console.log(result);
            dispatch(action);
        })
    }
}
export const getMoveList = (page) => {
    return (dispatch) => {
        // console.log('click');
        axios.get('/api/homeList.json?page=' + page).then((res) => {
            const result = res.data.data;
            // console.log(result);
            dispatch(addHomeList(result, page + 1))
        })
    }

}
export const toggleTopShow = (show) => {
    return {
        type: TOGGLE_SCROLL_TOP,
        show
    }
}